<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function getLongTime(arr) {
            if(arr.length === 0) {
                return 0
            }
            if(arr.length === 1) {
                return arr[0]
            }
            // dp 是当前最大项 dp = [arr[0],Math.max(2,1]--->dp = [2,2]
            const dp = [arr[0],Math.max(arr[0],arr[1])]
            for (let i = 2; i < arr.length; i++) {
                // 最优项[2] = Math.max(arr[2]+dp[i-2],dp[i-1])
                // 最优项[2] = Math.max(4+2,2)----> 最优项6
                dp[i] = Math.max(arr[i] + dp[i-2],dp[i-1])
            }
        }
        getLongTime([2,1,4,5,3,1,1,3])
    </script>
</body>
</html>